module.exports = {
  setSell (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setBuyRaw(`r-${text}`, config)
    } else {
      this.setSellRaw(text, config)
      if (this.strategy !== '1') {
        this.setStrategy('1', 'sets-1')
      }
    }
  },
  // 逆向卖出
  setSellByReverse (text, config) {
    // 这个卖出的优先级也比较高的，仅次于reason
    this.ifSellReverseTrend = true
    config = config || {}
    this.setSellRaw(text, config)
    if (this.strategy === '1') {
      this.setStrategy('2', 'setr-2')
    }
  },
  // 逆向卖出
  setSellByPreReverse (text, config) {
    this.ifSellPreReverseTrend = true
    config = config || {}
    this.setSellRaw(text, config)
    if (this.strategy === '1') {
      this.setStrategy('2', 'setr-2')
    }
  },
  setSellByPrePositive (text, config) {
    this.ifSellPrePositiveTrend = true
    config = config || {}
    this.setSellRaw(text, config)
    if (this.strategy === '2') {
      this.setStrategy('1', 'sets-1')
    }
  },
  // 原因的卖出
  setSellByReason (text, config) {
    config = config || {}
    // 如果信号级别小于原本的，那就不更新原因
    // 交易记录的应该还是新信号的，但是btb身上的是不能变的
    // if (this.hasKongPosition && this.ifOnlyPingKongByReason) {
    //   if (this.btbItem.direction_level >= config.level) {
    //   }
    // }
    this.ifOnlyPingKongByReason = true
    // 下个k平仓
    if (config.pingNextKline) {
      this.ifPingNextKlineLocal = true
    } else {
      this.ifPingNextKlineLocal = false
    }
    if (config.useRawPosition || config.useMaxPosition) {
      this.buySellRawTotalWalletBalance = true
    }
    if (config.useMaxPosition) {
      this.buySellRawTotalWalletBalance = true
      this.useMaxIndexBuySellPosition = true
    }
    if (config.leverage) {
      this.btbLeverage = config.leverage
    }
    this.setSellRaw(text, config)
    if (this.strategy !== '1') {
      this.setStrategy('1', 'sets-1')
    }
  },
  setBuy (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setSellRaw(`r-${text}`, config)
    } else {
      this.setBuyRaw(text, config)
      if (this.strategy !== '1') {
        this.setStrategy('1', 'setb-1')
      }
    }
  },
  // 原因的买入
  setBuyByReason (text, config) {
    config = config || {}
    this.ifOnlyPingDuoByReason = true
    // 下个k平仓
    if (config.pingNextKline) {
      this.ifPingNextKlineLocal = true
    } else {
      this.ifPingNextKlineLocal = false
    }
    if (config.useRawPosition || config.useMaxPosition) {
      this.buySellRawTotalWalletBalance = true
    }
    if (config.useMaxPosition) {
      this.buySellRawTotalWalletBalance = true
      this.useMaxIndexBuySellPosition = true
    }
    if (config.leverage) {
      this.btbLeverage = config.leverage
    }
    this.setBuyRaw(text, config)
    if (this.strategy !== '1') {
      this.setStrategy('1', 'sets-1')
    }
  },
  // 逆向买入
  setBuyByReverse (text, config) {
    // 这个买入的优先级也比较高的，仅次于reason
    this.ifBuyReverseTrend = true
    config = config || {}
    this.setBuyRaw(text, config)
    if (this.strategy === '1') {
      this.setStrategy('2', 'setr-2')
    }
  },
  // 逆向买入
  setBuyByPreReverse (text, config) {
    this.ifBuyPreReverseTrend = true
    config = config || {}
    this.setBuyRaw(text, config)
    if (this.strategy === '1') {
      this.setStrategy('2', 'setr-2')
    }
  },
  setBuyByPrePositive (text, config) {
    this.ifBuyPrePositiveTrend = true
    config = config || {}
    this.setBuyRaw(text, config)
    if (this.strategy === '2') {
      this.setStrategy('1', 'sets-1')
    }
  },
  setPingKong (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setPingDuoRaw(`r-${text}`, config)
    } else {
      this.setPingKongRaw(text, config)
    }
  },
  setPingDuo (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setPingKongRaw(`r-${text}`, config)
    } else {
      this.setPingDuoRaw(text, config)
    }
  },
  setNoBuy (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setNoSellRaw(`r-${text}`)
    } else {
      this.setNoBuyRaw(text)
    }
  },
  setNoSell (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setNoBuyRaw(`r-${text}`)
    } else {
      this.setNoSellRaw(text)
    }
  },
  setNoPingDuo (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setNoPingKongRaw(`r-${text}`)
    } else {
      this.setNoPingDuoRaw(text)
    }
  },
  setNoPingKong (text, config) {
    config = config || {}
    if (this.strategy === '2' && config.canReverse) {
      this.setNoPingDuoRaw(`r-${text}`)
    } else {
      this.setNoPingKongRaw(text)
    }
  },
  setSellRaw (text, config) {
    config = config || {}
    const rate = config.rate || 0.5
    this.sell = true
    this.buy = false
    this.pingKong = false
    this.buyRate = 0
    if (rate > this.sellRate) {
      this.sellRate = rate
    }
    if (config.level) {
      if (
        config.level > this.directionLevel ||
        this.directionType !== '空'
      ) {
        this.directionLevel = config.level
      }
    }
    if (config.coverPositionConfig && config.coverPositionConfig > this.coverPositionConfig) {
      this.coverPositionConfig = config.coverPositionConfig
    }
    if (config.minPositionConfig && config.minPositionConfig > this.minPositionConfig) {
      this.minPositionConfig = config.minPositionConfig
    }
    this.directionType = '空'
    if (!config.noCoverReason) {
      this.sellReason = text || ''
    }
    this.pingKongReason = ''
    this.buyReason = ''
    this.trackList.push({
      name: text || '',
      type: 'setSell',
      level: this.directionLevel
    })
  },
  setBuyRaw (text, config) {
    config = config || {}
    const rate = config.rate || 0.5
    this.buy = true
    this.sell = false
    this.pingDuo = false
    if (rate > this.buyRate) {
      this.buyRate = rate
    }
    if (config.level) {
      if (
        config.level > this.directionLevel ||
        this.directionType !== '多'
      ) {
        this.directionLevel = config.level
      }
    }
    if (config.coverPositionConfig && config.coverPositionConfig > this.coverPositionConfig) {
      this.coverPositionConfig = config.coverPositionConfig
    }
    if (config.minPositionConfig && config.minPositionConfig > this.minPositionConfig) {
      this.minPositionConfig = config.minPositionConfig
    }
    this.directionType = '多'
    this.sellRate = 0
    if (!config.noCoverReason) {
      this.buyReason = text || ''
    }
    this.pingDuoReason = ''
    this.sellReason = ''
    this.trackList.push({
      name: text || '',
      type: 'setBuy'
    })
  },
  setPingKongRaw (text, config) {
    config = config || {}
    const rate = config.rate || 1
    if (rate > this.pingKongRate) {
      this.pingKongRate = rate
    }
    this.pingKong = true
    this.pingKongReason = text || ''
    if (this.sell) {
      this.coverPositionConfig = 0
      this.minPositionConfig = 0
    }
    this.sell = false
    this.sellReason = ''
    this.sellRate = 0
    this.trackList.push({
      name: text || '',
      type: 'setPingKong'
    })
  },
  setPingDuoRaw (text, config) {
    config = config || {}
    const rate = config.rate || 1
    if (rate > this.pingDuoRate) {
      this.pingDuoRate = rate
    }
    this.pingDuo = true
    this.pingDuoReason = text || ''
    if (this.buy) {
      this.coverPositionConfig = 0
      this.minPositionConfig = 0
    }
    this.buy = false
    this.buyReason = ''
    this.buyRate = 0
    this.trackList.push({
      name: text || '',
      type: 'setPingDuo'
    })
  },
  setNoBuyRaw (text) {
    if (this.buy) {
      this.coverPositionConfig = 0
      this.minPositionConfig = 0
    }
    this.buy = false
    this.buyReason = ''
    this.buyRate = 0
    this.trackList.push({
      name: text || '',
      type: 'setNoBuy'
    })
  },
  setNoSellRaw (text) {
    if (this.sell) {
      this.coverPositionConfig = 0
      this.minPositionConfig = 0
    }
    this.sell = false
    this.sellReason = ''
    this.sellRate = 0
    this.trackList.push({
      name: text || '',
      type: 'setNoSell'
    })
  },
  setNoPingDuoRaw (text) {
    this.pingDuo = false
    this.pingDuoReason = ''
    this.pingDuoRate = 0
    this.trackList.push({
      name: text || '',
      type: 'setNoPingDuo'
    })
  },
  setNoPingKongRaw (text) {
    this.pingKong = false
    this.pingKongReason = ''
    this.pingKongRate = 0
    this.trackList.push({
      name: text || '',
      type: 'setNoPingKong'
    })
  },
  setNoExecuteRaw (text) {
    this.buy = false
    this.sell = false
    // this.pingKong = false
    // this.pingDuo = false
    this.trackList.push({
      name: text || '',
      type: 'setNoExecute'
    })
  }
}
